<?php namespace Summer\Shop\Models;

use Model;
use ApplicationException;

/**
 * Model
 */
class ScoreGoodsModel extends Model
{
    use \Winter\Storm\Database\Traits\Validation;
    

    /**
     * @var string The database table used by the model.
     */
    public $table = 'summer_shop_score_goods';

    /**
     * @var array Validation rules
     */
    public $rules = [
        'product_id' => 'required|unique:summer_shop_score_goods',
    ];

    public $belongsTo = [
        'product' => ['Summer\Shop\Models\ProductModel','key'=>'product_id','otherKey'=>'id']
    ];

    public function beforeSave()
    {
        if($this->product->is_with_variants){
            throw new ApplicationException('积分商品不能有变体');
        }
    }
}
